Grouping

one or more of the following steps:

  • Splitting the data into groups based on some criteria
  • Applying a function to each group independently
  • Combining the results into a data structure

In [1]:
import pandas as pd
import numpy as np

In [2]:
file_name_string = 'C:/Users/Charles Kelly/Desktop/Exercise Files/02_07/Begin/EmployeesWithGrades.xlsx'
employees_df = pd.read_excel(file_name_string, 'Sheet1', index_col=None, na_values=['NA'])

In [ ]:

group by Department

documentation: http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html

calculate total years of service by employees in each department


In [4]:
employees_df.groupby('Department').sum()


Out[4]:
YearsOfService
Department
Accounting 47
Engineering 60
Marketing 52

In [ ]: